<template>
	<view class="expert-page">
		<u-navbar title="紧急联系人" :autoBack="true" :placeholder="true" bgColor="rgba(255,255,255,0)"></u-navbar>
		<view class="content">
			<view class="tips">
				<view class="tips-title">
					<view class="line"></view>
					<view>
						添加紧急联系人
					</view>
				</view>
				<view class="tips-item">
					设置后仅在点击110报警时才会主动通知紧急联系人
				</view>
				<view class="tips-item">
					目前仅支持号码归属地为中国大陆的手机号码
				</view>
				<view class="tips-item">
					通知紧急联系人时会发送你当时所在地和联系方式
				</view>
			</view>
			<view class="info-item">
				<view class="item-title">
					姓名
				</view>
				<view class="info-right">
					<view class="item-text">
						<u-input v-model="name" placeholder="请输入紧急联系人姓名" border="none" inputAlign="right"></u-input>
					</view>
				</view>
			</view>
			<view class="info-item">
				<view class="item-title">
					电话
				</view>
				<view class="info-right">
					<view class="item-text">
						<u-input maxlength="11" type="number" v-model="tell" placeholder="请输入紧急联系人电话" border="none"
							inputAlign="right"></u-input>
					</view>
				</view>
			</view>
			<view class="save-btn">
				<u-button size="large" shape="circle" color="#5755F2" @click="updeta" type="primary" text="保存"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tell: '',
				name: '',
			}
		},
		onLoad() {
			this.getuserinfo()
		},
		methods: {
			updeta(){
				if(this.name == ''){
					uni.showToast({
						title:'请输入紧急联系人姓名！',
						icon:'none'
					})
					return
				}
				if(this.tell == ''){
					uni.showToast({
						title:'请输入紧急联系人电话！',
						icon:'none'
					})
					return
				}
				let params = {
					emergency_name:this.name,
					emergency_mobile:this.tell
				}
				uni.showLoading({
					mask:true
				})
				this.$Request({
					method: 'POST',
					url: '/api/user/profile',
					data: params,
					ismsg: true,
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						this.getuserinfo()
					}
				})
			},
			getuserinfo() {
				this.$Request({
					method: 'POST',
					url: '/api/user/getMyInfo',
					data: {},
					ismsg: false,
				}).then(res => {
					if (res.code == 1) {
						this.info = res.data
						this.tell = this.info.emergency_mobile
						this.name = this.info.emergency_name
					} else {
						this.info = {}
					}
				})
			},
		},
	}
</script>

<style>
	page {
		background-color: #F7F8FC;
	}
</style>
<style lang="scss" scoped>
	.expert-page {
		min-height: 100vh;
		background-image: url('https://m.lqvvvv.com/assets/static/index/nav-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 600rpx;

		.content {
			padding: 30rpx;
			margin-top: 30rpx;

			.tips {
				padding: 30rpx;
				background-color: #fff;
				border-radius: 30rpx;

				.tips-title {
					display: flex;
					align-items: center;
					font-size: 32rpx;
					color: #000;
					font-weight: bold;
					margin-bottom: 20rpx;

					.line {
						width: 6rpx;
						height: 28rpx;
						background: linear-gradient(180deg, #5755F2 0%, #CC7BFF 100%);
						border-radius: 5rpx;
						margin-right: 20rpx;
					}
				}

				.tips-item {
					color: #8B8DA0;
					font-size: 24rpx;
					margin-top: 10rpx;
				}
			}


			.info-item {
				background-color: #FFFFFF;
				padding: 30rpx;
				border-radius: 20rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 30rpx;

				.item-title {
					font-size: 28rpx;
					color: #000000;
					font-weight: bold;
				}

				.info-right {
					display: flex;
					align-items: center;

					.item-text {
						margin-right: 20rpx;
						font-size: 24rpx;
					}
				}

				.right-input {
					display: flex;
					align-items: center;

					image {
						width: 32rpx;
						height: 32rpx;
					}
				}
			}

			.save-btn {
				margin-top: 80rpx;
			}
		}
	}
</style>